var mySqrt = function(x) {
  if(x <2) return x
  let left = 0
  let right = x
  while(left < right - 1) {
    // console.log(left, right)
      const center = Math.floor((left+right)/2)
      const centerX = center*center
      if(centerX === x) return center 
      if(centerX< x) {
          left = center
      }else{
          right = center
      }
  }
  return Math.floor((left+right)/2)
};
console.log(mySqrt(8))